package com.zxtc.wh.servlet.appVersion;

import com.opensymphony.xwork2.ModelDriven;
import com.zxtc.wh.pojo.Result;
import com.zxtc.wh.pojo.appVersion.AppVersionBean;
import com.zxtc.wh.service.appVersion.AppUpdateVersionServiceImpl;
import com.zxtc.wh.service.appVersion.IAppUpdateVersionService;


/**
 */
//@Controller
public class AppUploadVersionAction implements ModelDriven<AppUploadVersionBean> {


    IAppUpdateVersionService service;
    Result<AppUploadVersionBean> result = new Result<>();
    AppUploadVersionBean bean = new AppUploadVersionBean();

    {
        service = new AppUpdateVersionServiceImpl();
    }


    @Override
    public AppUploadVersionBean getModel() {
        return bean;
    }


    public String json() throws Exception {
        try {
            //解析转换用户的输入为需要的格式
            AppVersionBean version = service.map(bean);
            //录入到数据库
            service.insert(version);

        } catch (RuntimeException e) {
            result.responseCode = 400;
            result.message = "请求被拒绝执行：" + e.getMessage();
            result.data = bean;
//            result.data = new Gson().toJson(bean);
        }

        return "success";
//        // 返回结果
//        Gson gson = new Gson();
//        String _data = gson.toJson(dataMap);
//        HttpServletResponse rep = ServletActionContext.getResponse();
//        rep.setContentType("application / json");
//        rep.getWriter().print(_data);
    }

    public Result<AppUploadVersionBean> getResult() {
        return result;
    }
}

